package com.thti.mecool.client.adapter;

import java.util.HashMap;

import com.thti.mecool.client.activity.R;
import com.thti.mecool.client.activity.TaskStepActionActivity;
import com.thti.mecool.client.model.biz.TaskStepBizImpl;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TaskOptionAdapter extends BaseAdapter {
	private String projectId,planId,taskId;
	public void setDataId(String projectId,String planId,String taskId) {
		this.projectId = projectId;
		this.planId=planId;
		this.taskId=taskId;
	}
	private int[] ActionIds = null;
	Context context;
	HashMap<String, Integer> finishStat;
	String[] newCert,StepIds;
	HashMap<String, Bitmap> hashMap;
	public TaskOptionAdapter(Context context, String[] newCert, int[] actionIds, HashMap<String, Integer> finishStat, String[] stepIds, HashMap<String, Bitmap> hashMap) {
		this.context=context;
		this.newCert=newCert;
		this.ActionIds=actionIds;
		this.finishStat=finishStat;
		this.StepIds=stepIds;
		this.hashMap=hashMap;
	}
	@Override
	public int getCount() {
		
		return newCert.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return newCert[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TextView task_option_item_text = null,tv2=null;
		ImageView task_option_item_img = null,finish = null;
//		if(convertView==null){
			convertView=LayoutInflater.from(context).inflate(R.layout.mecool_task_option_item, null);
			task_option_item_text=(TextView)convertView.findViewById(R.id.task_option_item_text);
			task_option_item_img=(ImageView)convertView.findViewById(R.id.task_option_item_img);
			finish=(ImageView)convertView.findViewById(R.id.mecool_task_option_item_finish);
			tv2=(TextView)convertView.findViewById(R.id.mecool_task_option_item_tv2);
			finish.setTag("isfinish");
			tv2.setTag("tv2");
//		}
		TaskStepBizImpl taskStepBizImpl=new TaskStepBizImpl(context);
		String data=taskStepBizImpl.findStepData(planId, projectId, taskId, taskId,StepIds[position]);
		if(data!=null){
			tv2.setText(data);
			tv2.setVisibility(0);
		}
		if(finish.isShown())
			finish.setVisibility(8);
		if(finishStat.get(StepIds[position])!=null){
			if(finishStat.get(StepIds[position])==1){
				finish.setVisibility(0);
			}else
				finish.setVisibility(8);
		}else{
			finish.setVisibility(8);
		}
		if(ActionIds[position]!=9)
			task_option_item_text.setText((position+1)+". "+newCert[position]);
		else
			task_option_item_text.setText(newCert[position]);
		switch (ActionIds[position]) {
		case 1:
			Bitmap bmp=hashMap.get(StepIds[position]);
			if(bmp!=null){
				task_option_item_img.setImageBitmap(bmp);
				task_option_item_img.setVisibility(0);}
			else
				task_option_item_img.setVisibility(0);
			break;
		case 2:
			task_option_item_img.setVisibility(8);
			break;
		case 9:
			finish.setVisibility(8);
			break;
		}
		return convertView;
	}

}
